package com.lwc.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(value = 1)
@Slf4j
public class AspectHandler {

    @Around("@annotation(time)")
    public Object timeAspect(ProceedingJoinPoint pjp, Time time) throws Throwable {
        String target = pjp.getTarget().getClass().getName();
        String name = pjp.getSignature().getName();
        long start = System.currentTimeMillis();
        Object proceed = pjp.proceed();
        long end = System.currentTimeMillis();
        log.warn("{}.{}():{} ms", target, name, end - start);
        return proceed;
    }
}
